package com.cbh.binlog.config;

import com.cbh.binlog.core.Entrance;
import com.cbh.binlog.link.factory.BinaryLogEventListenerFactory;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * 启动器注册器
 *
 * @author ChenBiHui
 * @date 2025/1/21
 */
public class EnableBinlogEventListenerRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
        //Registrar BinaryLogEventFactory
        BeanDefinitionBuilder factory = BeanDefinitionBuilder.genericBeanDefinition(BinaryLogEventListenerFactory.class);
        registry.registerBeanDefinition(BinaryLogEventListenerFactory.class.getName(), factory.getBeanDefinition());
        //Registrar Entrance
        BeanDefinitionBuilder entrance = BeanDefinitionBuilder.genericBeanDefinition(Entrance.class);
        entrance.addDependsOn(BinaryLogEventListenerFactory.class.getName());
        registry.registerBeanDefinition(Entrance.class.getName(), entrance.getBeanDefinition());
    }
}
